<?php
namespace Foxframe;

/**
 * @MappedSuperclass
 * @HasLifecycleCallbacks
 */
class Entity
{
	/**
	 * @Column(type="datetime")
	 */
	protected $dt_cadastro;

	/**
	 * @Column(type="datetime", nullable=true)
	 */
	protected $dt_alteracao;

	/**
	 * @Column(type="integer")
	 * @Version
	 */
	protected $version;


	public function get($attribute)
	{
		if (isset($this->$attribute))
			return $this->$attribute;
	}

	public function setVersion($version)
	{
		$this->version	= $version;
	}

	public function getDtCadastro()
	{
		return $this->dt_cadastro;
	}

	public function getDtAlteracao()
	{
		return $this->dt_alteracao;
	}

	/**
	 * @PrePersist
	 */
	public function prePersist()
	{
		$this->dt_cadastro	= new \DateTime();
	}

	/**
	 * @PreUpdate
	 */
	public function preUpdate()
	{
		$this->dt_alteracao	= new \DateTime();
	}
}
